//
//  CDUrlView.m
//  XKGN
//
//  Created by lzw on 2021/8/5.
//

#import "CDUrlView.h"
#import "UIColor+HEX.h"
#import "Masonry.h"

@interface CDUrlView () <UITableViewDelegate,UITableViewDataSource>

/* 视图 */
@property (nonatomic,strong) UITableView *tableView;

@property (nonatomic,  strong) UIVisualEffectView *blurView;

@property (nonatomic, strong) NSMutableDictionary *cellDic;

@end


@implementation CDUrlView

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        self.layer.cornerRadius = 7;
        self.layer.masksToBounds = YES;
        self.backgroundColor = [UIColor colorWithHex:0x000000 andAlpha:0.8];
        
//        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(photoPreviewCollectionViewDidScroll:) name:@"InstallRefreshData" object:nil];
        
        [self initSubViews:frame];
    }
    return self;
}

- (NSMutableDictionary *)cellDic {
    
    if (_cellDic == nil) {
        
        _cellDic = [NSMutableDictionary dictionary];
    }
    
    return _cellDic;;
}

#pragma mark - ***** setter 设置器/数据处理 *****

- (UITableView *)tableView {
    
    if (_tableView == nil) {
        
        _tableView = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain];
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.showsVerticalScrollIndicator = NO;
        
        
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.estimatedRowHeight = 44;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        
        _tableView.rowHeight = UITableViewCellSeparatorStyleNone;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        //这行代码必须加上，可以去除tableView的多余的线，否则会影响美观
        //        _tableView.tableFooterView = [UIView new];
        ///设置table没有分割线
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
        
//        [_tableView registerClass:[LWSwithCell class] forCellReuseIdentifier:@"LWSwithCell"];
        
    }
    
    return _tableView;
}

- (void)initSubViews:(CGRect)frame {
 
    self.blurView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
    
    self.blurView.frame = frame;
    [self addSubview:self.blurView];
    
    [self.blurView.contentView addSubview:self.tableView];
    
    self.headerView = [UIView new];
    
    self.headerView.frame = CGRectMake(0, 0, frame.size.width, 120);
    
    self.tableView.tableHeaderView = self.headerView;
    
    self.lable5 = [UILabel new];
    self.lable5.textColor = [UIColor whiteColor];
    self.lable5.font = [UIFont boldSystemFontOfSize:14];
    self.lable5.textAlignment = 1;
    self.lable5.text = @"长按单挑记录可复制";
    [self.headerView addSubview:self.lable5];
    
    [self.lable5 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.offset(0);
        make.top.offset(5);
        
    }];
    
    
}

#pragma mark tableDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.titleArr.count;
}


//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//
//    NSString *identifier = [self.cellDic objectForKey:[NSString stringWithFormat:@"LWSwithCell%@",indexPath]];
//    // 如果取出的唯一标示符不存在，则初始化唯一标示符，并将其存入字典中，对应唯一标示符注册Cell
//    if (identifier == nil) {
//        identifier = [NSString stringWithFormat:@"%@%@", @"LWSwithCell", [NSString stringWithFormat:@"%@", indexPath]];
//        [self.cellDic setValue:identifier forKey:[NSString stringWithFormat:@"%@", indexPath]];
//        // 注册Cell
//        [self.tableView registerClass:[LWSwithCell class] forCellReuseIdentifier:identifier];
//    }
//
//    LWSwithCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
//
//    cell.titleLab.text = self.titleArr[indexPath.row];
//
//    cell.switchBtn.tag = indexPath.row;
//
//    [cell.switchBtn addTarget:self action:@selector(titleSwitchClck:) forControlEvents:UIControlEventTouchUpInside];
//
//
//    return cell;
//}
///点击cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    
//    [[CDModelClick sharepayManger] playFuncName:self.titleArr[indexPath.row] andState:YES];
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    return 36;
}


@end
